#include <stdio.h>
#include <python3.5/Python.h>
#include "call_py.h"
//车牌识别
//2021-5-7

//python对象初始化
struct python_obj* python_init(struct python_obj *pobj)
{
    Py_Initialize();
    if(!Py_IsInitialized())
    {
        printf("init err!\n");
        return NULL;
    }

    PyRun_SimpleString("import sys");
    PyRun_SimpleString("sys.path.append('../py/')");
    pobj->p_Module=PyImport_ImportModule("lpr");
    pobj->p_Fun=PyObject_GetAttrString(pobj->p_Module,"get_msg");
    pobj->p_Args=PyTuple_New(1);

    return pobj;
}

//调用python车牌识别函数
struct python_obj* python_call(struct python_obj *pobj,const char *filename)
{
    char *p;
    PyTuple_SetItem(pobj->p_Args,0,Py_BuildValue("s",filename));

    pobj->p_Ret=PyEval_CallObject(pobj->p_Fun,pobj->p_Args);
    PyArg_Parse(pobj->p_Ret,"s",&p); 
    pobj->car_id = p;
  
    //printf("%s\n",p);

    return pobj;
}
/*
//销毁python对象
#define python_destory Py_Finalize
*/
